#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Some helpful functions for turning query results into dictionaries.

    >>> from tack.lib.dicttools import query_to_list, rows_to_dicts
    >>> query_to_list([[1,2,3],[4,5,6],[7,8,9]],['one','two','three'])
    [{'three': 3, 'two': 2, 'one': 1}, {'three': 6, 'two': 5, 'one': 4}, {'three': 9, 'two': 8, 'one': 7}]

    >>> list(rows_to_dicts([[1,2,3],[4,5,6],[7,8,9]],['one','two','three']))
    [{'three': 3, 'two': 2, 'one': 1}, {'three': 6, 'two': 5, 'one': 4}, {'three': 9, 'two': 8, 'one': 7}]
"""

def query_to_list(rows, labels):
    return list(rows_to_dicts(rows, labels))

def rows_to_dicts(rows, labels):
    return (dict((n, r[i]) for i, n in enumerate(labels)) for r in rows)
